import requests
import argparse
URL = 'http://1.94.105.22:8080/api/upload'


def upload_files(user_name, file_paths):
    files = []
    for i, file_path in enumerate(file_paths):
        file = open(file_path, 'rb')
        files.append(('files', (file)))
    response = requests.post(
        URL, files=files, data={'user_name': user_name},
        verify=False)
    return response.status_code, response.text


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("user_name", help="输入用户名")
    parser.add_argument("file_paths", nargs="+", help="输入文件列表")
    args = parser.parse_args()
    print(args.user_name)
    print(args.file_paths)
    status, text = upload_files(args.user_name, args.file_paths)
    print("返回状态码"+str(status))
    print("返回消息"+str(text))
